const SECRECT = "s4aajsid4yh"
const jwt = require("jsonwebtoken")
// 颁发jwt
exports.public = function(res,maxAge = 3600 * 24 * 7,info = {}){
    const token = jwt.sign(info,SECRECT,{
        expiresIn:maxAge
    })
    return token
}
// 验证jwt
exports.verify = function(req){
    
    let token = req.headers.authorization
    
    if(!token){
        return null;
    }
    token = token.split(' ')
    token = token.length === 1 ? token[0] : token[1]

    try{
        const res = jwt.verify(token,SECRECT)
        return res;
    }catch(err){
        return null
    }

}